package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.Response;
import com.zhijian.medical.entity.po.MeetingRoom;
import com.zhijian.medical.entity.vo.request.MeetingAppointmentSearchVo;
import com.zhijian.medical.entity.vo.request.MeetingAppointmentSingleVo;
import com.zhijian.medical.entity.vo.request.MeetingRoomApplyVo;
import com.zhijian.medical.entity.vo.request.MeetingRoomSearchVo;
import com.zhijian.medical.entity.vo.response.MeetingAppointmentVo;
import com.zhijian.medical.entity.vo.response.MeetingRoomDayVo;
import com.zhijian.medical.entity.vo.response.MeetingRoomVo;
import com.zhijian.medical.holder.CurrentUserHolder;
import com.zhijian.medical.service.MeetingAppointmentService;
import com.zhijian.medical.service.MeetingRoomService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 会议室 控制层
 *
 * @author HCG
 * @version 1.0
 * @date 2023-09-26 09:57:34
 */
@Slf4j
@Controller
@Api(tags = "会议室预约管理")
public class MeetingRoomController {

    @Autowired
    private MeetingRoomService service;

    @Autowired
    private MeetingAppointmentService meetingAppointmentService;

    /**
     * 新增
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/room")
    @ApiOperation("新增会议室")
    public boolean insert(@RequestBody MeetingRoom param) {
        log.info("{} - {}| insert info", this.getClass().getSimpleName(), param);
        return service.insert(param) != null;
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Response
    @DeleteMapping("/meeting/room/{id}")
    @ApiOperation("删除会议室")
    public boolean delete(@PathVariable("id") Long id) {
        log.info("{} - {}| delete info", this.getClass().getSimpleName(), id);
        service.deleteById(id);
        return true;
    }

    /**
     * 修改
     *
     * @param id
     * @param param
     * @return
     */
    @Response
    @PutMapping("/meeting/room/{id}")
    @ApiOperation("修改会议室")
    public boolean update(@PathVariable("id") Long id, @RequestBody MeetingRoom param) {
        log.info("{} - {}| update info, {}", this.getClass().getSimpleName(), id, param);
        param.setId(id);
        return service.update(param);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Response
    @GetMapping("/meeting/room/{id}")
    @ApiOperation("根据id查询会议室")
    public MeetingRoomVo selectById(@PathVariable("id") Long id) {
        log.info("{} - {}| query info", this.getClass().getSimpleName(), id);
        return service.selectVoById(id);
    }

    /**
     * 分页查询
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/room/page")
    @ApiOperation("分页查询会议室")
    public Page<MeetingRoomVo> selectByCondition(@RequestBody(required = false) MeetingRoomSearchVo param) {
        if (param == null)
            param = MeetingRoomSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return service.selectPage(param);
    }

    /**
     * 查询某一天的所有会议室的可预约记录与已预约记录
     *
     * @param day
     * @return
     */
    @Response
    @GetMapping("/meeting/room/day")
    @ApiOperation("查询某一天的所有会议室的可预约记录与已预约记录")
    public List<MeetingRoomDayVo> selectMeetingRoomDayListByDay(@ApiParam(name = "day", value = "天，格式'20230101'") @RequestParam(value = "day")
                                                                        String day) {
        return service.selectMeetingRoomDayListByDay(day);
    }

    /**
     * 申请某个会议室的预约
     *
     * @param meetingRoomApplyVo
     * @return
     */
    @Response
    @PostMapping("/meeting/room/apply")
    @ApiOperation("申请某个会议室的预约")
    public boolean apply(@RequestBody MeetingRoomApplyVo meetingRoomApplyVo) {
        meetingRoomApplyVo.setUserId(CurrentUserHolder.getUser().getId());
        return service.apply(meetingRoomApplyVo);
    }

    /**
     * 分页查询会议预约记录
     *
     * @param param
     * @return
     */
    @Response
    @PostMapping("/meeting/appointment/page")
    @ApiOperation("分页查询会议预约记录")
    public Page<MeetingAppointmentVo> selectByCondition(@RequestBody(required = false) MeetingAppointmentSearchVo param) {
        if (param == null)
            param = MeetingAppointmentSearchVo.builder().build();
        log.info("{} - {}| query info", this.getClass().getSimpleName(), param);
        return meetingAppointmentService.selectPage(param);
    }

    /**
     * 单个格子的预约详情
     *
     * @param meetingAppointmentSingleVo
     * @return
     */
    @Response
    @PostMapping("/meeting/appointment/single")
    @ApiOperation("单个格子的预约详情")
    public MeetingAppointmentVo single(@RequestBody MeetingAppointmentSingleVo meetingAppointmentSingleVo) {
        return meetingAppointmentService.single(meetingAppointmentSingleVo);
    }

}